Amazon Bedrock Knowledge bases の RetrieveAndGenerate API で Claude 3.5 Sonnet が利用可能になりました。

Amazon Bedrock Knowledge bases の RetrieveAndGenerate API で Claude 3.5 Sonnet が利用可能になりました。

Amazon Bedrock Knowledge bases の RetrieveAndGenerate API で Claude 3.5 Sonnet が利用可能になりました。今回から Converse API 経由でモデルが実行されるようになっています。
Clock Icon2024.08.24

こんにちは!AWS 事業本部コンサルティング部のたかくに(@takakuni_)です。

Amazon Bedrock Knowledge bases の RetrieveAndGenerate API で Claude 3.5 Sonnet が利用可能になりました。

https://aws.amazon.com/about-aws/whats-new/2024/08/knowledge-bases-amazon-bedrock-anthropics-claude-3-5-sonnet/

Claude 3.5 Sonnet が登場して 2 ヶ月で、他のサービスでもマネージドに利用可能になってくるアジリティの高さ、 AWS の本気度が伝わってきますね。

https://dev.classmethod.jp/articles/claude-35-sonnet-new-anthropic-ai-model/

アップデート内容

アップデート前までのおさらいをします。

今回アップデートがあったのは RetrieveAndGenerate API で Claude 3.5 Sonnet が利用可能になったという点です。

つまり何が言いたいかというと、今回のアップデート以前からやろうと思えば Amazon Bedrock Knowledge bases と合わせて Claude 3.5 が使えたということです。

Knowlege bases for Amazon Bedrock には RAG としての取り出しに 2 つの API があります。(大昔から触っている方は、耳タコだと思うのですっ飛ばしてもらって構いません。)

  • Retrieve API
  • RetrieveAndGenerate API

図にすると、以下のようなイメージです。

Retrieve API はエンべディングモデルを利用して、プロンプトのエンべディング、ベクトルデータベースへの検索、検索結果の表示までを行います。

retrieve api.png

RetrieveAndGenerate API は Retrieve API のプロンプトのエンべディング、ベクトルデータベースへの検索に加え、検索結果からテキスト生成モデルを利用して回答生成まで行います。

retrieveandgenerate api.png

RetrieveAndGenerate API は回答生成まで行ってくれる分、とてもシンプルなアプリケーションの作りになります。

ただし、テキスト生成で利用できるモデルには制限があるため、モデルの自由度の高めたいケース(回答生成には OpenAI 社のモデルを使いたい等)では Retrieve API で取得した検索結果をテキスト生成モデルに渡すような処理を実装する必要があります。

Claude 3.5 Sonnet が RetrieveAndGenerate API にサポートする以前は、次のテキスト生成モデルが利用可能でした。

  • Claude 3 Sonnet
  • Claude 3 Haiku
  • Claude 2
  • Claude 2.1
  • Claude Instant 1.2

今回のアップデートで Claude 3.5 Sonnet が追加され、 Amazon Bedrock Knowledge bases では Claude 3 Opus 以外の Claude 3 ファミリーがサポートとなりました。[1]

また、東京リージョンも Claude 3.5 Sonnet の RetrieveAndGenerate API が利用可能です。

Anthropic’s Claude 3.5 Sonnet model support for Amazon Bedrock Knowledge Bases is now generally available in the US East (N. Virginia), US West (Oregon), Europe (Frankfurt) and Asia Pacific (Tokyo) AWS Regions.

クオーター

東京リージョンや RetrieveAndGenerate API でのモデル実行もサポートされたし、 Claude 3.5 Sonnet を使ってみるか!と思う前にクォーターを確認しましょう。

Runtime quotas, API requests per second, Knowledge base quotas がナレッジベースに大きくに関わるポイントです。

API requests per second, Knowledge base quotas はリージョンで変わりませんが、 Runtime quotas はリージョンで大きく異なっていますね。まとめると次になります。

Anthropic Claude 3.5 Sonnet

リージョン 1 分間に処理されるリクエスト数 1 分間に処理されるトークン数 サービスクォータで調整可能かどうか
us-west-2 250 2,000,000 いいえ
ap-northeast-1 20 200,000 いいえ
ap-southeast-1 20 200,000 いいえ
eu-central-1 20 200,000 いいえ
それ以外 50 400,000 いいえ

最新情報は以下をご覧ください。

Quotas for Amazon Bedrock - Amazon Bedrock

もしも、東京リージョン(ap-northeast-1)で Claude 3.5 Sonnet の RetrieveAndGenerate API を利用する場合は、想定しているユースケースにパフォーマンスが耐えられるかお気をつけください。

やってみる

それでは Claude 3.5 Sonnet を利用してナレッジベースを検証してみます。今回は構成をオレゴンリージョンにデプロイして検証します。

Untitled.png

利用した Terraform のコードはこちらです。

https://github.com/takakuni-classmethod/genai-blog/tree/main/knowledge_bases_pinecone_serverless

Advanced parsing options

Amazon Bedrock Knowledge bases ではオプションで、文書から非テキスト情報(表やグラフなど)を解析するために、テキスト生成モデルを利用できます。この機能のことを Advanced parsing options と言います。

利用できるモデルは Claude 3 Sonnet と Claude 3 Haiku と記載がありますが、念の為作成できるか試してみました。

Currently, Claude 3 Sonnet and Claude 3 Haiku are supported.

Advanced parsing options

CloudShell 上に次のファイルを用意します。

data-source-configuration.json
{
	"type": "S3",
	"s3Configuration": {
		"bucketArn": "arn:aws:s3:::バケット名",
		"bucketOwnerAccountId": "アカウントID"
	}
}
vector-ingestion-configuration.json
{
  "parsingConfiguration": {
    "bedrockFoundationModelConfiguration": {
      "modelArn": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0"
    },
    "parsingStrategy": "BEDROCK_FOUNDATION_MODEL"
  }
}

データソースを作成するコマンドを実行したところ、ドキュメントの通りまだサポートはしていない様子でした。

[cloudshell-user@ip-10-140-16-205 ~]$ aws bedrock-agent create-data-source --region us-west-2 \
>   --name "s3-data-source-claude3-5" \
>   --knowledge-base-id "XXXXXXXX" \
>   --data-deletion-policy "DELETE" \
>   --data-source-configuration file://data-source-configuration.json \
>   --vector-ingestion-configuration file://vector-ingestion-configuration.json

An error occurred (ValidationException) when calling the CreateDataSource operation: Invalid Bedrock Foundation Model Parser Provided. Check your input and try again

クエリの実行

クエリの実行を試してみます。

次のコードを使用して、クエリ分割機能のオン/オフの 2 段階で検証してみます。まずはオフの状態から。

index.py
import boto3

KNOWLEDGEBASE_ID = "295SHUIWOD"  # ナレッジベース ID を記載
model_arn = "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0"
bedrock_agent = boto3.client("bedrock-agent-runtime", region_name="us-west-2")

prompt = (
    "Amazon Bedrock って何ですか?"
)

response = bedrock_agent.retrieve_and_generate(
    input={"text": prompt},
    retrieveAndGenerateConfiguration={
        "type": "KNOWLEDGE_BASE",
        "knowledgeBaseConfiguration": {
            "knowledgeBaseId": KNOWLEDGEBASE_ID,
            "modelArn": model_arn,
            # "orchestrationConfiguration": {
            #     "queryTransformationConfiguration": {"type": "QUERY_DECOMPOSITION"}
            # },
        },
    },
)
print(response["output"]["text"],flush=False)

しっかり回答できていますね。素晴らしい

(app-py3.12) takakuni@ app % python index.py
Amazon Bedrockは、高性能な基盤モデル(Foundation Models、FMs)を提供する完全マネージド型サービスです。主要なAIスタートアップやAmazonが開発したモデルを統一されたAPIを通じて利用できます。このサービスでは、幅広い基盤モデルから自分のユースケースに最適なものを選択できます。

Bedrockは、セキュリティ、プライバシー、責任あるAIを考慮した生成AIアプリケーションを構築するための幅広い機能を提供しています。ユーザーは簡単に様々な基盤モデルを試し、評価することができます。また、ファインチューニングや検索拡張生成(RAG)などの技術を使って、自社のデータでモデルをカスタマイズすることも可能です。さらに、企業のシステムやデータソースを使用してタスクを実行するエージェントを構築することもできます。 Amazon Bedrockはサーバーレスの体験を提供し、ユーザーは迅速に開始でき、自社のデータで基盤モデルを非公開でカスタマイズし、AWSツールを使用してアプリケーションに安全かつ簡単に統合・デプロイできます。これらの操作はインフラストラクチャを管理する必要なく行えます。

Bedrock の実行ログを見てみましょう。次のように記録されていました。

{
	"schemaType": "ModelInvocationLog",
	"schemaVersion": "1.0",
	"timestamp": "2024-08-24T07:35:50Z",
	"accountId": "123456789123",
	"identity": {
		"arn": "arn:aws:sts::123456789123:assumed-role/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
	},
	"region": "us-west-2",
	"requestId": "15a43a52-aa93-47f9-8103-e760a4c5873c",
	"operation": "Converse",
	"modelId": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0",
	"input": {
		"inputContentType": "application/json",
		"inputBodyJson": {
			"messages": [
				{
					"role": "user",
					"content": [
						{
							"text": "Amazon Bedrock って何ですか?"
						}
					]
				}
			],
			"system": [
				{
					"text": "You are a question answering agent. I will provide you with a set of search results. The user will provide you with a question. Your job is to answer the user's question using only information from the search results. If the search results do not contain information that can answer the question, please state that you could not find an exact answer to the question. Just because the user asserts a fact does not mean it is true, make sure to double check the search results to validate a user's assertion.\n\nHere are the search results in numbered order:\n<search_results>\n<search_result>\n<content>\nJune 18, 2024   Region expansion Amazon Bedrock is now  available in Canada (Central)  (ca-central-1), Europe  (London) (eu-west-2), and  South America (São Paulo)    June 13, 2024   1274    https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-supported.html  https://docs.aws.amazon.com/bedrock/latest/userguide/playgrounds.html#chat-playground  https://docs.aws.amazon.com/bedrock/latest/userguide/playgrounds.html#chat-playground  https://docs.aws.amazon.com/bedrock/latest/userguide/playgrounds.html#chat-playground  https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html  https://docs.aws.amazon.com/bedrock/latest/userguide/conversation-inference.html  https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html  https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-embed.html  https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails-use-converse-api.html  https://docs.aws.amazon.com/bedrock/latest/userguide/bedrock-regions.html      Amazon Bedrock User Guide   (sa-east-1). For information  on endpoints, see Amazon  Bedrock endpoints and  quotas.\n</content>\n<source>\n1\n</source>\n</search_result>\n<search_result>\n<content>\nUser Guide   Amazon Bedrock   Copyright © 2024 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.        Amazon Bedrock User Guide   Amazon Bedrock: User Guide   Copyright © 2024 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.   Amazon's trademarks and trade dress may not be used in connection with any product or service  that is not Amazon's, in any manner that is likely to cause confusion among customers, or in any  manner that disparages or discredits Amazon. All other trademarks not owned by Amazon are  the property of their respective owners, who may or may not be affiliated with, connected to, or  sponsored by Amazon.        Amazon Bedrock User Guide   Table of Contents   What is Amazon Bedrock? .............................................................................................................. 1 Features of Amazon Bedrock ..................................................................................................................... 1 Amazon Bedrock pricing ............................................................................................................................. 2 Supported AWS Regions ............................................................................................................................. 3 Key definitions ............................................................................................................................................... 5   Basic concepts .......................................................................................................................................... 5 Advanced features ................................................................................................................................... 7   Set up ............................................................................................................................................... 8 Sign up for an AWS account ...................................................................................................................... 8 Create a user with administrative access ................................................................................................ 9 Grant programmatic access ..................................................................................................................... 10 Console access ............................................................................................................................................ 12 Model access ............................................................................................................................................... 12   Add model access ................................................................................................................................. 13 Remove model access ..........................................................................................................................\n</content>\n<source>\n2\n</source>\n</search_result>\n<search_result>\n<content>\n......... 1285   xiii        Amazon Bedrock User Guide   What is Amazon Bedrock?   Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs)  from leading AI startups and Amazon available for your use through a unified API. You can choose  from a wide range of foundation models to find the model that is best suited for your use case.  Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.   Topics   • Features of Amazon Bedrock   • Amazon Bedrock pricing   • Supported AWS Regions   • Key definitions   Features of Amazon Bedrock   Take advantage of Amazon Bedrock foundation models to explore the following capabilities. To see  feature limitations by Region, see Model support by AWS Region.\n</content>\n<source>\n3\n</source>\n</search_result>\n<search_result>\n<content>\n...................................................................................................................... 1285   xiii        Amazon Bedrock User Guide   What is Amazon Bedrock?   Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs)  from leading AI startups and Amazon available for your use through a unified API. You can choose  from a wide range of foundation models to find the model that is best suited for your use case.  Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.   Topics   • Features of Amazon Bedrock   • Amazon Bedrock pricing   • Supported AWS Regions   • Key definitions   Features of Amazon Bedrock   Take advantage of Amazon Bedrock foundation models to explore the following capabilities. To see  feature limitations by Region, see Model support by AWS Region.\n</content>\n<source>\n4\n</source>\n</search_result>\n<search_result>\n<content>\n............................................ 1247 Learn more about AWS CloudFormation .......................................................................................... 1248   Quotas ........................................................................................................................................ 1249 API reference ............................................................................................................................. 1273 Document history ...................................................................................................................... 1274 AWS Glossary ............................................................................................................................. 1285   xiii        Amazon Bedrock User Guide   What is Amazon Bedrock?   Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs)  from leading AI startups and Amazon available for your use through a unified API. You can choose  from a wide range of foundation models to find the model that is best suited for your use case.  Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.\n</content>\n<source>\n5\n</source>\n</search_result>\n\n</search_results>\n\nYou should provide your answer without any inline citations or references to specific sources within the answer text itself. Do not include phrases like \"according to source X\", \"[1]\", \"[source 2, 3]\", etc within your <text> tags.\n\nHowever, you should include <sources> tags at the end of each <answer_part> to specify which source(s) the information came from.\nNote that <sources> may contain multiple <source> if you include information from multiple results in your answer.\n\nDo NOT directly quote the <search_results> in your answer. Your job is to answer the user's question as concisely as possible.\n\nYou must output your answer in the following format. Pay attention and follow the formatting and spacing exactly:\n<answer>\n<answer_part>\n<text>\nfirst answer text\n</text>\n<sources>\n<source>source ID</source>\n</sources>\n</answer_part>\n<answer_part>\n<text>\nsecond answer text\n</text>\n<sources>\n<source>source ID</source>\n</sources>\n</answer_part>\n</answer>\n"
				}
			],
			"inferenceConfig": {
				"maxTokens": 2048,
				"temperature": 0,
				"topP": 1,
				"stopSequences": ["\nObservation"]
			}
		},
		"inputTokenCount": 2152
	},
	"output": {
		"outputContentType": "application/json",
		"outputBodyJson": {
			"output": {
				"message": {
					"role": "assistant",
					"content": [
						{
							"text": "<answer>\n<answer_part>\n<text>\nAmazon Bedrockは、高性能な基盤モデル(Foundation Models、FMs)を提供する完全マネージド型サービスです。主要なAIスタートアップやAmazonが開発したモデルを統一されたAPIを通じて利用できます。このサービスでは、幅広い基盤モデルから自分のユースケースに最適なものを選択できます。\n\nBedrockは、セキュリティ、プライバシー、責任あるAIを考慮した生成AIアプリケーションを構築するための幅広い機能を提供しています。ユーザーは簡単に様々な基盤モデルを試し、評価することができます。また、ファインチューニングや検索拡張生成(RAG)などの技術を使って、自社のデータでモデルをカスタマイズすることも可能です。さらに、企業のシステムやデータソースを使用してタスクを実行するエージェントを構築することもできます。\n</text>\n<sources>\n<source>3</source>\n<source>4</source>\n<source>5</source>\n</sources>\n</answer_part>\n<answer_part>\n<text>\nAmazon Bedrockはサーバーレスの体験を提供し、ユーザーは迅速に開始でき、自社のデータで基盤モデルを非公開でカスタマイズし、AWSツールを使用してアプリケーションに安全かつ簡単に統合・デプロイできます。これらの操作はインフラストラクチャを管理する必要なく行えます。\n</text>\n<sources>\n<source>3</source>\n<source>4</source>\n<source>5</source>\n</sources>\n</answer_part>\n</answer>"
						}
					]
				}
			},
			"stopReason": "end_turn",
			"metrics": {
				"latencyMs": 8868
			},
			"usage": {
				"inputTokens": 2152,
				"outputTokens": 524,
				"totalTokens": 2676
			}
		},
		"outputTokenCount": 524
	}
}

ログを見て何かお気づきでしょうか?

そう、 Claude 3.5 Sonnet からは Converse API に変わっています。(Claude 3 Sonnet や Claude 3 Haiku は InvokeModel API でした)

変化があって、おもしろいですね。

続いてクエリ分割オプションを有効化して再度実行します。

python
import boto3

KNOWLEDGEBASE_ID = "295SHUIWOD"  # ナレッジベース ID を記載
model_arn = "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0"
bedrock_agent = boto3.client("bedrock-agent-runtime", region_name="us-west-2")

prompt = (
    "Amazon Bedrock って何ですか?"
)

response = bedrock_agent.retrieve_and_generate(
    input={"text": prompt},
    retrieveAndGenerateConfiguration={
        "type": "KNOWLEDGE_BASE",
        "knowledgeBaseConfiguration": {
            "knowledgeBaseId": KNOWLEDGEBASE_ID,
            "modelArn": model_arn,
-            # "orchestrationConfiguration": {
-            #     "queryTransformationConfiguration": {"type": "QUERY_DECOMPOSITION"}
-            # },
+            "orchestrationConfiguration": {
+                "queryTransformationConfiguration": {"type": "QUERY_DECOMPOSITION"}
+            },
        },
    },
)
print(response["output"]["text"],flush=False)

こちらもクエリ分割の中身については触れませんが、うまく動いてそうです。

(app-py3.12) takakuni@HL01556 app % python index.py
Amazon Bedrock は、高性能な基盤モデル(Foundation Models、FMs)を提供する完全マネージド型サービスです。主要なAIスタートアップやAmazonが開発したモデルを統一されたAPIを通じて利用できます。ユーザーは幅広い基盤モデルから、自身のユースケースに最適なものを選択することができます。

Bedrockは、セキュリティ、プライバシー、責任あるAIを考慮した生成AIアプリケーションを構築するための幅広い機能を提供します。ユーザーは簡単に様々な基盤モデルを試し、評価することができ、ファインチューニングや検索拡張生成(RAG)などの技術を使って自社のデータでモデルをカスタマイズすることも可能です。さらに、企業のシステムやデータソースを使用してタスクを実行するエージェントを構築することもできます。 Amazon Bedrockはサーバーレスの体験を提供し、ユーザーは迅速に開始でき、自社のデータで基盤モデルをプライベートにカスタマイズし、AWSツールを使用してアプリケーションに簡単かつ安全に統合・デプロイすることができます。これらの操作はインフラストラクチャを管理する必要なく行えます。

参考までにクエリ分割で行われるモデルの実行も Converse API で行われていました。

クエリ分割フェーズのログ.json
{
	"schemaType": "ModelInvocationLog",
	"schemaVersion": "1.0",
	"timestamp": "2024-08-24T07:45:19Z",
	"accountId": "123456789123",
	"identity": {
		"arn": "arn:aws:sts::123456789123:assumed-role/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
	},
	"region": "us-west-2",
	"requestId": "5471e436-74bc-463a-91f2-4d4274e41ce3",
	"operation": "Converse",
	"modelId": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0",
	"input": {
		"inputContentType": "application/json",
		"inputBodyJson": {
			"messages": [
				{
					"role": "user",
					"content": [
						{
							"text": "Amazon Bedrock って何ですか?"
						}
					]
				}
			],
			"system": [
				{
					"text": "You are a query generation agent. Given the conversation history (optional) and a user question, your task is to determine the optimal queries.\n\nYou should consider the following two steps:\nStep 1. If conversation history is available, decide if the user question misses any necessary context. If so, rewrite the user question to be a standalone question that captures the relevant context from the given conversation history.\nStep 2. Decide if the standalone question is a complex question. If so, decompose it into a set of relevant queries, which can be easier to answer.\n\nPlease pay attention to the conversation history. If the user question is already a standalone question, you can skip Step 1.\nIf the standalone question does not require a further decomposition, you can skip Step 2.\n\nHere’s an example for Step 1:\n\n<example>\nInput:\n<conversation_history>\n<conversation>\n<question>How many vehicles can I include in a quote in Kansas</question>\n<answer>You can include 5 vehicles in a quote if you live in Kansas</answer>\n</conversation>\n</conversation_history>\n\nUser: What about texas?\n\nOutput:\n<generated_queries><standalone_question>How many vehicles can be included in a quote in Texas?<standalone_question></generated_queries>\n</example>\n\nHere are two examples for Step 2:\n\n<example>\nInput:\n\nUser: Were both of the following rock groups formed in California: Dig and Thinking Fellers Union Local 282?\n\nOutput:\n<generated_queries><standalone_question>Were both of the following rock groups formed in California: Dig and Thinking Fellers Union Local 282?</standalone_question><query>What is the formation place of rock group Dig?</query><query>What is the formation place of the rock group Thinking Fellers Union Local 282?</query></generated_queries>\n</example>\n\n<example>\nInput:\n\nUser: in 2018 , what percentage of undeveloped acres were located in the u.s?\n\nOutput:\n<generated_queries><standalone_question>in 2018 , what percentage of undeveloped acres were located in the u.s?</standalone_question><query>the net undeveloped acres in 2018 of u.s.</query><query>the total net undeveloped acres in 2018</query></generated_queries>\n</example>\n\nHere is the current conversation history:\n<conversation_history>\n\n</conversation_history>\n\nPlease output your response between <generated_queries> </generated_queries> tags, the standalone question within <standalone_question> </standalone_question> and each decomposed query within <query> </query> tags.\n"
				}
			],
			"inferenceConfig": {
				"maxTokens": 2048,
				"temperature": 0,
				"topP": 1,
				"stopSequences": ["\nObservation"]
			}
		},
		"inputTokenCount": 618
	},
	"output": {
		"outputContentType": "application/json",
		"outputBodyJson": {
			"output": {
				"message": {
					"role": "assistant",
					"content": [
						{
							"text": "<generated_queries>\n<standalone_question>Amazon Bedrock とは何ですか?</standalone_question>\n<query>Amazon Bedrock の定義と概要</query>\n<query>Amazon Bedrock の主な特徴や機能</query>\n<query>Amazon Bedrock の用途や活用事例</query>\n</generated_queries>"
						}
					]
				}
			},
			"stopReason": "end_turn",
			"metrics": {
				"latencyMs": 1824
			},
			"usage": {
				"inputTokens": 618,
				"outputTokens": 92,
				"totalTokens": 710
			}
		},
		"outputTokenCount": 92
	}
}
回答生成フェーズのログ.json
{
	"schemaType": "ModelInvocationLog",
	"schemaVersion": "1.0",
	"timestamp": "2024-08-24T07:45:21Z",
	"accountId": "123456789123",
	"identity": {
		"arn": "arn:aws:sts::123456789123:assumed-role/XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
	},
	"region": "us-west-2",
	"requestId": "c17be2e4-0d08-469d-9489-305eef6645f4",
	"operation": "Converse",
	"modelId": "arn:aws:bedrock:us-west-2::foundation-model/anthropic.claude-3-5-sonnet-20240620-v1:0",
	"input": {
		"inputContentType": "application/json",
		"inputBodyJson": {
			"messages": [
				{
					"role": "user",
					"content": [
						{
							"text": "Amazon Bedrock とは何ですか?"
						}
					]
				}
			],
			"system": [
				{
					"text": "You are a question answering agent. I will provide you with a set of search results. The user will provide you with a question. Your job is to answer the user's question using only information from the search results. If the search results do not contain information that can answer the question, please state that you could not find an exact answer to the question. Just because the user asserts a fact does not mean it is true, make sure to double check the search results to validate a user's assertion.\n\nHere are the search results in numbered order:\n<search_results>\n<search_result>\n<content>\nAmazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.   Topics   • Features of Amazon Bedrock   • Amazon Bedrock pricing   • Supported AWS Regions   • Key definitions   Features of Amazon Bedrock   Take advantage of Amazon Bedrock foundation models to explore the following capabilities. To see  feature limitations by Region, see Model support by AWS Region.   • Experiment with prompts and configurations – Run model inference by sending prompts using  different configurations and foundation models to generate responses. You can use the API or  the text, image, and chat playgrounds in the console to experiment in a graphical interface.  When you're ready, set up your application to make requests to the InvokeModel APIs.\n</content>\n<source>\n1\n</source>\n</search_result>\n<search_result>\n<content>\nWhen you're ready, set up your application to make requests to the InvokeModel APIs.   • Augment response generation with information from your data sources – Create knowledge  bases by uploading data sources to be queried in order to augment a foundation model's  generation of responses.   Features of Amazon Bedrock 1        Amazon Bedrock User Guide   • Create applications that reason through how to help a customer – Build agents that use  foundation models, make API calls, and (optionally) query knowledge bases in order to reason  through and carry out tasks for your customers.   • Adapt models to specific tasks and domains with training data – Customize an Amazon  Bedrock foundation model by providing training data for fine-tuning or continued-pretraining in  order to adjust a model's parameters and improve its performance on specific tasks or in certain  domains.   • Improve your FM-based application's efficiency and output – Purchase Provisioned Throughput for a foundation model in order to run inference on models more efficiently and at discounted  rates.   • Determine the best model for your use case – Evaluate outputs of different models with built-in  or custom prompt datasets to determine the model that is best suited for your application.   Note   Model evaluation is in preview release for Amazon Bedrock and is subject to change.\n</content>\n<source>\n2\n</source>\n</search_result>\n<search_result>\n<content>\n......... 1285   xiii        Amazon Bedrock User Guide   What is Amazon Bedrock?   Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs)  from leading AI startups and Amazon available for your use through a unified API. You can choose  from a wide range of foundation models to find the model that is best suited for your use case.  Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.   Topics   • Features of Amazon Bedrock   • Amazon Bedrock pricing   • Supported AWS Regions   • Key definitions   Features of Amazon Bedrock   Take advantage of Amazon Bedrock foundation models to explore the following capabilities. To see  feature limitations by Region, see Model support by AWS Region.\n</content>\n<source>\n3\n</source>\n</search_result>\n<search_result>\n<content>\n............................................ 1247 Learn more about AWS CloudFormation .......................................................................................... 1248   Quotas ........................................................................................................................................ 1249 API reference ............................................................................................................................. 1273 Document history ...................................................................................................................... 1274 AWS Glossary ............................................................................................................................. 1285   xiii        Amazon Bedrock User Guide   What is Amazon Bedrock?   Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs)  from leading AI startups and Amazon available for your use through a unified API. You can choose  from a wide range of foundation models to find the model that is best suited for your use case.  Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.\n</content>\n<source>\n4\n</source>\n</search_result>\n<search_result>\n<content>\n...................................................................................................................... 1285   xiii        Amazon Bedrock User Guide   What is Amazon Bedrock?   Amazon Bedrock is a fully managed service that makes high-performing foundation models (FMs)  from leading AI startups and Amazon available for your use through a unified API. You can choose  from a wide range of foundation models to find the model that is best suited for your use case.  Amazon Bedrock also offers a broad set of capabilities to build generative AI applications with  security, privacy, and responsible AI. Using Amazon Bedrock, you can easily experiment with and  evaluate top foundation models for your use cases, privately customize them with your data using  techniques such as fine-tuning and Retrieval Augmented Generation (RAG), and build agents that  execute tasks using your enterprise systems and data sources.   With Amazon Bedrock's serverless experience, you can get started quickly, privately customize  foundation models with your own data, and easily and securely integrate and deploy them into  your applications using AWS tools without having to manage any infrastructure.   Topics   • Features of Amazon Bedrock   • Amazon Bedrock pricing   • Supported AWS Regions   • Key definitions   Features of Amazon Bedrock   Take advantage of Amazon Bedrock foundation models to explore the following capabilities. To see  feature limitations by Region, see Model support by AWS Region.\n</content>\n<source>\n5\n</source>\n</search_result>\n\n</search_results>\n\nYou should provide your answer without any inline citations or references to specific sources within the answer text itself. Do not include phrases like \"according to source X\", \"[1]\", \"[source 2, 3]\", etc within your <text> tags.\n\nHowever, you should include <sources> tags at the end of each <answer_part> to specify which source(s) the information came from.\nNote that <sources> may contain multiple <source> if you include information from multiple results in your answer.\n\nDo NOT directly quote the <search_results> in your answer. Your job is to answer the user's question as concisely as possible.\n\nYou must output your answer in the following format. Pay attention and follow the formatting and spacing exactly:\n<answer>\n<answer_part>\n<text>\nfirst answer text\n</text>\n<sources>\n<source>source ID</source>\n</sources>\n</answer_part>\n<answer_part>\n<text>\nsecond answer text\n</text>\n<sources>\n<source>source ID</source>\n</sources>\n</answer_part>\n</answer>\n"
				}
			],
			"inferenceConfig": {
				"maxTokens": 2048,
				"temperature": 0,
				"topP": 1,
				"stopSequences": ["\nObservation"]
			}
		},
		"inputTokenCount": 2070
	},
	"output": {
		"outputContentType": "application/json",
		"outputBodyJson": {
			"output": {
				"message": {
					"role": "assistant",
					"content": [
						{
							"text": "<answer>\n<answer_part>\n<text>\nAmazon Bedrock は、高性能な基盤モデル(Foundation Models、FMs)を提供する完全マネージド型サービスです。主要なAIスタートアップやAmazonから提供される多様な基盤モデルを、統一されたAPIを通じて利用することができます。ユーザーは自身のユースケースに最適なモデルを幅広い選択肢から選ぶことができます。\n\nAmazon Bedrockは、セキュリティ、プライバシー、責任あるAIを備えた生成AIアプリケーションを構築するための幅広い機能を提供しています。ユーザーは簡単に基盤モデルを実験・評価し、ファインチューニングや検索拡張生成(RAG)などの技術を使用して自社のデータで私的にカスタマイズすることができます。また、企業のシステムやデータソースを使用してタスクを実行するエージェントを構築することも可能です。\n</text>\n<sources>\n<source>3</source>\n<source>4</source>\n<source>5</source>\n</sources>\n</answer_part>\n<answer_part>\n<text>\nAmazon Bedrockはサーバーレスの体験を提供し、ユーザーは迅速に開始し、自社のデータで基盤モデルを私的にカスタマイズし、AWSツールを使用してアプリケーションに簡単かつ安全に統合・デプロイすることができます。これらの操作はインフラストラクチャを管理する必要なく行うことができます。\n</text>\n<sources>\n<source>1</source>\n<source>4</source>\n<source>5</source>\n</sources>\n</answer_part>\n</answer>"
						}
					]
				}
			},
			"stopReason": "end_turn",
			"metrics": {
				"latencyMs": 9034
			},
			"usage": {
				"inputTokens": 2070,
				"outputTokens": 523,
				"totalTokens": 2593
			}
		},
		"outputTokenCount": 523
	}
}

まとめ

以上、「Amazon Bedrock Knowledge bases の RetrieveAndGenerate API で Claude 3.5 Sonnet が利用可能になりました。」でした。

モデルのクォーターが東京リージョンだと少し気になりますが、Amazon Bedrock Knowledge bases のアップデートの中でも大きいものだと私は思います。

このブログがどなたかの参考になれば幸いです。AWS 事業本部コンサルティング部のたかくに(@takakuni_)でした!

脚注
  1. 個人的には Claude 3 Opus は 1 分間あたり 50 回までのハードリミットがあるため、 RAG 向きかと言われると少し微妙な印象です。 ↩︎

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.